# -*- coding: utf-8 -*-
# @Time: 2023/4/14 23:46
# @File: views.py
# @Desc:


from flask import Blueprint, send_from_directory, current_app

bp_media = Blueprint("media", __name__, url_prefix="/media")


# /media/avatar/abc.jpg
# 部署的时候，在nginx中配置一个/meida前缀的url
# 访问/media的时候，我们指定让他从media文件夹下寻找文件
@bp_media.route("/avatar/<filename>")
def get_avatar(filename):
    return send_from_directory(current_app.config['AVATARS_SAVE_PATH'], filename)


# 获取帖子图片视图函数
@bp_media.route("/post/<filename>")
def get_post_image(filename):
    return send_from_directory(current_app.config["POST_IMAGE_SAVE_PATH"], filename)


# 获取轮播图图片视图函数
@bp_media.route("/banner/<filename>")
def get_banner_image(filename):
    return send_from_directory(current_app.config["BANNER_IMAGE_SAVE_PATH"], filename)
